<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
        <title>发表分享-品购网</title>
        <link href="__PUBLIC__/css/hangye.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/css/person.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/css/comm.css" rel="stylesheet" type="text/css" />
		<link href="__PUBLIC__/css/panel.css" rel="stylesheet" type="text/css" />
        <link href="__PUBLIC__/js/auto/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
        <script type="text/javascript" src="__PUBLIC__/js/auto/jquery.autocomplete.js"></script>
        <script type="text/javascript" src="__PUBLIC__/js/ckeditor/ckeditor.js"></script>
        <script src="__PUBLIC__/js/ajaxupload.js" type="text/javascript"></script>

    </head>
    <body>
	   <div class="containner">
        <include file="Index:header"/>
        <!--导航结束-->
    <div id="myshare" style="position:absolute;top:0px;margin:auto;z-index:299"></div>
    <div class="body-center">
<!--        <div class="path">
	   首页 >> 个人页面 >> 发表分享
        </div>-->
                <div class="w_tithead"> <strong>您当前的位置是： </strong><a href="__APP__">品购网首页</a><a  href="#">个人信息</a>发表分享</div>

        <div class="persion_title">最新分享</div>
        <div class="contents">
            <div class="menu">
                <include file="User:user_menu"/>

            </div>
            <form method="post" action="__APP__/Home/Share/add" onsubmit="return checkForm();">
                <div class="content">
                    <div class="select">
                        <div class="selectitems" id="searchBrand">
                            品牌：<input type="text" class="selectinput" size="13" name="brand" id="brand_input" value="请选择或新建" onclick="autoContent('__APP__/Home/Share/autoBrand/','brand_input');">
                            <br>
                        </div>

                        <div class="selectitems" id="searchCategory">
                            品类：<input type="text"  class="selectinput"size="13" name="category" id="categoryInput" value="请选择或新建" onclick="autoContent('__APP__/Home/Share/autoCategory/','categoryInput');">
                            <br>
                        </div>

                        <div class="selectitems" id="searchCommodity">
                            品名：<input type="text" class="selectinput" size="13" name="commodity" id="commodityInput" value="请选择或新建" onclick="autoContent('__APP__/Home/Share/autoCommodity/','commodityInput');">
                            <br>
                        </div>
                    </div>

                    <div id="addtextarea" class="addinput">
                        标题：<input type="text" name="title" id="title" size="50">
                        <textarea name="content" id="content" rows="20" cols="92"></textarea>
                        <br>
                        请选择分享所属行业：
                        <foreach name="hangye" item="one">
                            <input type="radio" name="industry" value="{$key}" >{$one}
                        </foreach>
                        <input type="image" src="__PUBLIC__/images/submit.gif" align="right" id="submitadd" style="cursor:pointer;">
                        <input id="upload_button" type="button" value="添加相关图片（限于png，gif，jpg，jpeg格式，大小限制3M" />
                    </div>
                </div>
            </form>
        </div>
    </div>
<include file="Index:bottom" />
<!--页尾部分-->
</div>
</body>
</html>


<script>

    function checkForm(){
        var title = $("#title").val();
//        var content = $("#content").val();
        var content= CKEDITOR.instances.content.getData();

        var brand_input = $("#brand_input").val();
        var categoryInput = $("#categoryInput").val();
        var commodityInput = $("#commodityInput").val();

        var industry = $("input[@type=radio][checked]").val();

        var industry = $(":radio:checked");

        if( brand_input.length<1 || title.length > 100 || brand_input=='请选择或新建'){
            alert('品牌输入非法');
            return false;
        }
        if(categoryInput.length<1 || title.length > 100 || categoryInput=='请选择或新建'){
            alert('品类输入非法');
            return false;
        }
        if(commodityInput.length<1 || title.length > 100 || commodityInput=='请选择或新建'){
            alert('品名输入非法');
            return false;
        }


        //alert(content);
        if(title.length<1 || title.length > 200){
            alert('标题输入非法');
            return false;
        }
        content = DelHtml(content);
        if(content.length<1){
            alert('正文输入非法');
            return false;
        }
        if(industry.length<=0){
            alert("请选择所属行业");
            return false;
        }
        return true;

    }
    function DelHtml(Word){
        a = Word.indexOf("<");
        b = Word.indexOf(">");
        len = Word.length;
        c = Word.substring(0, a);
        if(b == -1)
            b = a;
        d = Word.substring((b + 1), len);
        Word = c + d;
        tagCheck = Word.indexOf("<");
        if(tagCheck != -1)
            Word = DelHtml(Word);
        return Word;
    }

    function autoContent(url,obj){
        if($("#"+obj).val() == '请选择或新建'){
            $("#"+obj).val('');
        }

        bValue = null;
        cValue = null;
        if(obj=='categoryInput'){
            bValue = $("#brand_input").val();
        }
        else if(obj=='commodityInput'){
            cValue = $("#categoryInput").val();
            bValue = $("#brand_input").val();
        }

        $("#"+obj).autocomplete(url, {
            width: 230,
            max:10,
            dataType: "json",
            autoFill :false,
            minChars:0,
            selectFirst:false,
            extraParams: {b:bValue,c:cValue},
            scrollHeight: 300,
            parse: function(data) {
                //alert(data);
                if(data.length >= 1){
                    return $.map(eval(data), function(row) {
                        res = row.split('-');
                        return {
                            data: row,
                            value: res[1] ,
                            result: res[1]
                        }
                    });
                }
            },
            formatItem: function(item) {
                if(item.length > 1){
                    item = item.split('-');
                    return "<table width='90%'><tr><td align = \"left\">" + item[0] +"</td>"+"<td align = \"right\">"+ item[1]+"</td></tr></table>";
                }
            }
        });
    }
    CKEDITOR.replace( 'content',{skin : 'kama'});
    $(document).ready(function(){

        var button = $('#upload_button'), interval;
        var fileType = "all",fileNum = "one";

        new AjaxUpload(button,{
            action: '__URL__/uploadPic',
            /*data:{
            'buttoninfo':button.text()
        },*/
            name: 'photo',
            onSubmit : function(file, ext){

            },
            onComplete: function(file, response){
                if(response != "success"){
                    img = '<img id="user_pic" align=center src="__ROOT__/Public/Uploads/thumb_'+ response+"\"/>";
                    CKEDITOR.instances.content.insertHtml(img);

                    window.clearInterval(interval);

                }
                if(response == "success"){
                    alert('图片类型错误，请重试！');
                }
            }
        });

    });
</script>

